package cn.ming.leo.service;

import org.springframework.stereotype.Service;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.PagedList;

import cn.ming.leo.bean.Door;
import cn.ming.leo.utils.Message;
import cn.ming.leo.utils.PageListModel;

@Service
public class DoorService {

	public Message<Door> getById(int id) {
		return new Message<Door>(Door.find.byId("" + id));
	}

	public Message<PageListModel<Door>> findAll(Integer pageIndex, Integer pageSize) {
		PagedList<Door> pl;
		ExpressionList<Door> pression = Ebean.find(Door.class).where();

		pageIndex = (pageIndex == null) ? 0 : pageIndex - 1;
		pageSize = (pageSize == null) ? 10 : pageSize;

		pl = pression.order().desc("create_time").findPagedList(pageIndex, pageSize);

		PageListModel<Door> pageListModel = new PageListModel<Door>(pl);

		return new Message<PageListModel<Door>>(pageListModel);
	}

}
